﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using GPCSC.IDAL;
using Maticsoft.DBUtility;//�����������
namespace GPCSC.SQLServerDAL
{
    /// <summary>
    /// ���ݷ�����CL_POST_S��
    /// </summary>
    public class CL_POST_S : ICL_POST_S
    {
        public CL_POST_S()
        { }
        #region  ��Ա����

        /// <summary>
        /// �Ƿ���ڸü�¼
        /// </summary>
        public bool Exists(Guid CL_POST_SOID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from CL_POST_S");
            strSql.Append(" where CL_POST_SOID=@CL_POST_SOID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CL_POST_SOID", SqlDbType.UniqueIdentifier)};
            parameters[0].Value = CL_POST_SOID;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// ����һ������
        /// </summary>
        public void Add(GPCSC.Model.CL_POST_S model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into CL_POST_S(");
            strSql.Append("CL_POST_SOID,PD_CompanyInfoSOID_PK,PD_CompanyName,POSTNAME,REMARK,status,Depth,CL_PARPOSTID_PK,PARPOSTNAME,Tab,Number)");
            strSql.Append(" values (");
            strSql.Append("@CL_POST_SOID,@PD_CompanyInfoSOID_PK,@PD_CompanyName,@POSTNAME,@REMARK,@status,@Depth,@CL_PARPOSTID_PK,@PARPOSTNAME,@Tab,@Number)");
            SqlParameter[] parameters = {
					new SqlParameter("@CL_POST_SOID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@PD_CompanyInfoSOID_PK", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@PD_CompanyName", SqlDbType.VarChar,50),
					new SqlParameter("@POSTNAME", SqlDbType.VarChar,50),
					new SqlParameter("@REMARK", SqlDbType.VarChar,200),
					new SqlParameter("@status", SqlDbType.Int,4),
					new SqlParameter("@Depth", SqlDbType.Int,4),
					new SqlParameter("@CL_PARPOSTID_PK", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@PARPOSTNAME", SqlDbType.VarChar,50),
					new SqlParameter("@Tab", SqlDbType.VarChar,50),
					new SqlParameter("@Number", SqlDbType.Int,4)};
            parameters[0].Value = model.CL_POST_SOID;
            parameters[1].Value = model.PD_CompanyInfoSOID_PK;
            parameters[2].Value = model.PD_CompanyName;
            parameters[3].Value = model.POSTNAME;
            parameters[4].Value = model.REMARK;
            parameters[5].Value = model.status;
            parameters[6].Value = model.Depth;
            parameters[7].Value = model.CL_PARPOSTID_PK;
            parameters[8].Value = model.PARPOSTNAME;
            parameters[9].Value = model.Tab;
            parameters[10].Value = model.Number;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// ����һ������
        /// </summary>
        public void Update(GPCSC.Model.CL_POST_S model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update CL_POST_S set ");
            strSql.Append("PD_CompanyInfoSOID_PK=@PD_CompanyInfoSOID_PK,");
            strSql.Append("PD_CompanyName=@PD_CompanyName,");
            strSql.Append("POSTNAME=@POSTNAME,");
            strSql.Append("REMARK=@REMARK,");
            strSql.Append("status=@status,");
            strSql.Append("Depth=@Depth,");
            strSql.Append("CL_PARPOSTID_PK=@CL_PARPOSTID_PK,");
            strSql.Append("PARPOSTNAME=@PARPOSTNAME,");
            strSql.Append("Tab=@Tab,");
            strSql.Append("Number=@Number");
            strSql.Append(" where CL_POST_SOID=@CL_POST_SOID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CL_POST_SOID", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@PD_CompanyInfoSOID_PK", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@PD_CompanyName", SqlDbType.VarChar,50),
					new SqlParameter("@POSTNAME", SqlDbType.VarChar,50),
					new SqlParameter("@REMARK", SqlDbType.VarChar,200),
					new SqlParameter("@status", SqlDbType.Int,4),
					new SqlParameter("@Depth", SqlDbType.Int,4),
					new SqlParameter("@CL_PARPOSTID_PK", SqlDbType.UniqueIdentifier,16),
					new SqlParameter("@PARPOSTNAME", SqlDbType.VarChar,50),
					new SqlParameter("@Tab", SqlDbType.VarChar,50),
					new SqlParameter("@Number", SqlDbType.Int,4)};
            parameters[0].Value = model.CL_POST_SOID;
            parameters[1].Value = model.PD_CompanyInfoSOID_PK;
            parameters[2].Value = model.PD_CompanyName;
            parameters[3].Value = model.POSTNAME;
            parameters[4].Value = model.REMARK;
            parameters[5].Value = model.status;
            parameters[6].Value = model.Depth;
            parameters[7].Value = model.CL_PARPOSTID_PK;
            parameters[8].Value = model.PARPOSTNAME;
            parameters[9].Value = model.Tab;
            parameters[10].Value = model.Number;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// ɾ��һ������
        /// </summary>
        public void Delete(Guid CL_POST_SOID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete CL_POST_S ");
            strSql.Append(" where CL_POST_SOID=@CL_POST_SOID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CL_POST_SOID", SqlDbType.UniqueIdentifier)};
            parameters[0].Value = CL_POST_SOID;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// �õ�һ������ʵ��
        /// </summary>
        public GPCSC.Model.CL_POST_S GetModel(Guid CL_POST_SOID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 CL_POST_SOID,PD_CompanyInfoSOID_PK,PD_CompanyName,POSTNAME,REMARK,status,Depth,CL_PARPOSTID_PK,PARPOSTNAME,Tab,Number from CL_POST_S ");
            strSql.Append(" where CL_POST_SOID=@CL_POST_SOID ");
            SqlParameter[] parameters = {
					new SqlParameter("@CL_POST_SOID", SqlDbType.UniqueIdentifier)};
            parameters[0].Value = CL_POST_SOID;

            GPCSC.Model.CL_POST_S model = new GPCSC.Model.CL_POST_S();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["CL_POST_SOID"].ToString() != "")
                {
                    model.CL_POST_SOID = new Guid(ds.Tables[0].Rows[0]["CL_POST_SOID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PD_CompanyInfoSOID_PK"].ToString() != "")
                {
                    model.PD_CompanyInfoSOID_PK = new Guid(ds.Tables[0].Rows[0]["PD_CompanyInfoSOID_PK"].ToString());
                }
                model.PD_CompanyName = ds.Tables[0].Rows[0]["PD_CompanyName"].ToString();
                model.POSTNAME = ds.Tables[0].Rows[0]["POSTNAME"].ToString();
                model.REMARK = ds.Tables[0].Rows[0]["REMARK"].ToString();
                if (ds.Tables[0].Rows[0]["status"].ToString() != "")
                {
                    model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Depth"].ToString() != "")
                {
                    model.Depth = int.Parse(ds.Tables[0].Rows[0]["Depth"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CL_PARPOSTID_PK"].ToString() != "")
                {
                    model.CL_PARPOSTID_PK = new Guid(ds.Tables[0].Rows[0]["CL_PARPOSTID_PK"].ToString());
                }
                model.PARPOSTNAME = ds.Tables[0].Rows[0]["PARPOSTNAME"].ToString();
                model.Tab = ds.Tables[0].Rows[0]["Tab"].ToString();
                if (ds.Tables[0].Rows[0]["Number"].ToString() != "")
                {
                    model.Number = int.Parse(ds.Tables[0].Rows[0]["Number"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// ��������б�
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select CL_POST_SOID,PD_CompanyInfoSOID_PK,PD_CompanyName,POSTNAME,REMARK,status,Depth,CL_PARPOSTID_PK,PARPOSTNAME,Tab,Number ");
            strSql.Append(" FROM CL_POST_S ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// ��ҳ��ȡ�����б�
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "CL_POST_S";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  ��Ա����
    }
}

